﻿<%@ WebHandler Language="C#" Class="detail" %>
using Models;
using System;
using System.Web;
using Newtonsoft.Json;
using System.Linq;
using System.Collections.Generic;

public class detail : IHttpHandler {

    public void ProcessRequest (HttpContext context) {
        context.Response.ContentType = "text/plain";


        string authtoken = context.Request.Headers["X-ACCESS-USER"];//Header中的token

        var code = 1;
        var msg = "用户信息";
        var time = DateTime.Now;

        if (string.IsNullOrEmpty(authtoken))
        {
            HttpContext.Current.Response.Write("parameter error");
            return;
        }
        using (Entities bll = new Entities())
        {
           
                
                
              var x = bll.User.FirstOrDefault(p => p.UOpenID == authtoken);

            if (x != null)
            {

                var data = new
                {
                    id = x.UID,

                    token = x.UGuid,
                    group = new { name = _rky.getUstat(x.Ustate.ToString()), image = "https://js.50cms.com/up/jg.png" },
                    xinji = x.Ustate,
                    levename = _rky.getUstat(x.Ustate.ToString()),
                    is_store = x.Ustate,
                    x.isMember,
                    avatar = x.UHeadImg,
                    username = x.UNickName,
                    nickname = x.UNickName,
                    phone_number = x.UTel,
                    user_type = x.isMember

                };

                context.Response.Write(JsonConvert.SerializeObject(new { code, msg, time, data }));
            }

            else
            { 

   
               var  wxuser = new User();
                wxuser.UGuid = _rky.GenerateStringID();
                wxuser.UOpenID = authtoken;
                wxuser.Ustate = 0;
                wxuser.Ujifen = 0;
                wxuser.RegTime = DateTime.Now;
                wxuser.isMember = 0;  //直
                bll.User.Add(wxuser);
                bll.SaveChanges();


                context.Response.Write(JsonConvert.SerializeObject(new { code, msg="注册chenggong",time,data=wxuser })); 
                
             }


        }

        HttpContext.Current.Response.End();
        //context.Response.Write("Hello World");


    }





    public bool IsReusable {
        get {
            return false;
        }
    }

}